package org.smr.ministore.entities.covert;

import org.apache.commons.collections4.CollectionUtils;
import org.smr.ministore.entities.Brand;
import org.smr.ministore.entities.BrandOrgan;


import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 */
public class CovertUtils {

    /**
     * 把品牌信息转换成组织归属品牌
     * @param brand 品牌
     * @return BrandOrgan
     */
    public static BrandOrgan covert2BrandOrgan(Brand brand) {
        BrandOrgan brandOrgan = new BrandOrgan();
        brandOrgan.setBrand(brand);
        brandOrgan.setBrandId(brand.getId());
        brandOrgan.setOrganId(brand.getAssignee().getId());
        brandOrgan.setBrandCode(brand.getBrandCode());
        brandOrgan.setBrandName(brand.getBrandName());
        brandOrgan.setCreateDate(brand.getCreateDate());
        brandOrgan.setUpdateDate(brand.getUpdateDate());
        return brandOrgan;
    }

    /**
     *
     * @param brands
     * @return
     */
    public static List<BrandOrgan> batchCovert2BrandOrgan(List<Brand> brands) {
        if(CollectionUtils.isEmpty(brands)){
            return Collections.EMPTY_LIST;
        }
        List<BrandOrgan> brandOrgans = brands.stream().map(CovertUtils::covert2BrandOrgan).collect(Collectors.toList());
        return brandOrgans;
    }



}
